package com.zhongxi.guoyuan.adapter.coinPost;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.coinPost.LogisiticsData;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * Created by Administrator on 2017/7/8 19:09.
 */

public class LogisiticsInfoAdapter extends BaseAdapter {

    Context context;
    List<LogisiticsData.Traces> list;
    private LogisiticsData.Traces traces;

    public LogisiticsInfoAdapter(Context context) {
        this.context = context;
        list=new ArrayList<>();
    }

    public void setList(List<LogisiticsData.Traces> list) {
        this.list = list;
        Collections.reverse(list);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size()!=0?list.size():0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LogisiticsInfoAdapter.ViewHolder holder = null;
        try{
            if(convertView == null){
                holder = new LogisiticsInfoAdapter.ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.item_logisitics_info, parent, false);

                holder.ivImg= (ImageView) convertView.findViewById(R.id.logisitisc_point);
                holder.tvName= (TextView) convertView.findViewById(R.id.logisitics_info_case);
                holder.tvTime= (TextView) convertView.findViewById(R.id.logisitics_info_time);
                holder.hasArrived= (TextView) convertView.findViewById(R.id.hasArrived);
                convertView.setTag(holder);
            }else{
                holder = (LogisiticsInfoAdapter.ViewHolder) convertView.getTag();
            }
            traces = list.get(position);
            if (traces != null) {
                if (position==0){
                    holder.ivImg.setVisibility(View.INVISIBLE);
                    holder.hasArrived.setVisibility(View.VISIBLE);
                    holder.tvName.setTextColor(context.getResources().getColor(R.color.bg_yield));
                    holder.tvTime.setTextColor(context.getResources().getColor(R.color.bg_yield));
                }else {
                    holder.hasArrived.setVisibility(View.INVISIBLE);
                    holder.ivImg.setVisibility(View.VISIBLE);
                    holder.ivImg.setImageResource(R.mipmap.logisitics_show);
                    holder.tvName.setTextColor(context.getResources().getColor(R.color.gohere));
                    holder.tvTime.setTextColor(context.getResources().getColor(R.color.gohere));
                }
                holder.tvName.setText(traces.getAcceptStation());
                holder.tvTime.setText(traces.getAcceptTime());
            }

        }catch (Exception e){
            e.printStackTrace();
        }
        return convertView;
    }

    class ViewHolder{
        private ImageView ivImg;
        private TextView tvName;
        private TextView tvTime;
        private TextView  hasArrived;
    }
}
